/*
 * sstack.c
 *
 *  Created on: 2009-5-24
 *      Author: hwg
 */


#include "../header/common.h"

Status InitStack_C(sstack *S)
{

	S->base = malloc(STACK_INIT_SIZE *sizeof(elemtype_c));
	S->top = S->base;
	S->stack_size = STACK_INIT_SIZE;

	return ok;
}

Status Push_C(sstack *S, elemtype_c e)
{
	if(S->top - S->base >= S->stack_size)
	{
		S->base = realloc(S->base, (S->stack_size + STACK_INCREMENT)*sizeof(elemtype_c));
		S->top=S->base + S->stack_size;
		S->stack_size += STACK_INCREMENT;
	}
	*(S->top++) = e;
	return ok;
}


Status Pop_C(sstack *S, elemtype_c *e)
{
	if (StackEmpty_C(S))return error;
	*e = *--S->top;
	return ok;
}


Status GetTop_C(sstack *S, elemtype_c *e)
{
	if (StackEmpty_C(S))return error;
	*e = *(S->top-1);
	return ok;
}

Status StackEmpty_C(sstack *S)
{
	if(S->top == S->base)
	{
    		return error;
	}else{
		return ok;
	}
}

